﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YasharEl.Infrastructure.EntityModel;

namespace YasharEl.Infrastructure.PersistenceModel.EntityFramework
{
    /// <summary>
    /// Helper class to convert Entity Framework DbContext to various data providers.
    /// </summary>
    public class EntityFrameworkUnitOfWorkConvertor : IUnitOfWorkConvertor
    {
        /// <summary>
        /// Gets <see cref="IQueryable"/> from <see cref="DataContext"/> wrapped
        /// in the given <see cref="LinqToSqlUnitOfWork"/> instance.
        /// </summary>
        public IQueryable<TEntity> ToQueryable<TEntity, TIdentity>(IUnitOfWork unitOfWork) where TEntity : class, IGenericEntity<TIdentity>
        {
            return (unitOfWork as EntityFrameworkUnitOfWork).DbContext.Set<TEntity>();
        }
    }
}
